<?php /*
*/
$connect = mysql_connect("localhost","root","");
 mysql_select_db("php_studentform");
?>
<script type="text/javascript">
function degreeopt()
{
	var degreetext = document.getElementById("degreeid").value;
	var degreeinput = document.getElementById("degreeoption");
	if(degreetext == "other")
	{
	degreeinput.style.display ='block';
	}
	else
	{
	degreeinput.style.display ='none';
	}
}

function ocopt()
{
	var ocid = document.getElementById("ocid").value;
	var ocuoption = document.getElementById("ocuoption");
	if(ocid == "other")
	{
	ocuoption.style.display ='block';
	}
	else
	{
	ocuoption.style.display ='none';
	}
}
</script>
<form action="ex4.php" method="post">
<label>Name</label>
<input type="text" value="" id="name" name="name" /><br><br>
<label>Age</label>
<input type="text" value="" id="age" name="age" /><br><br>
<label>Gender</label>
<select type="option" name="gender" >
<option>Select Gender</option>
<option value="male">Male</option>
<option value="female">Female</option>
</select><br><br>
<label>Date</label>
<input type="text" value="" id="date" name="date" /><br><br>
<label>Degree</label>
<select type="option" name="degree" onchange="degreeopt()" id="degreeid">
<option>Select Degree</option>
<option value="be">BE</option>
<option value="btech">BTECH</option>
<option value="dr">DR</option>
<option value="other">Others</option>
</select><br>
<input type="text" name="degreeoption" id="degreeoption" style="display:none;"/><br><br>
<label>Occupation</label>
<select type="option" name="occupation" onchange="ocopt()" id="ocid" >
<option>Select Occupation</option>
<option value="it">IT</option>
<option value="nit">Non-IT</option>
<option value="dr">DOCTOR</option>
<option value="other">Others</option>
</select><br>
<input type="text" name="ocuoption" id="ocuoption" style="display:none;"/>
<br>
<input type="submit" value="save" name="personalform"/><br>
</form>

<?php
//print_r($_POST);
if(isset($_POST['personalform'])) 
{
$name = $_POST['name'];
$age = $_POST['age'];
$gender = $_POST['gender'];
$date = $_POST['date'];
$degree = $_POST['degree'];
$occupation = $_POST['occupation'];
//$student = $_POST['student-id'];
$degreeoption = $_POST['degreeoption'];
$ocuoption = $_POST['ocuoption'];
$degreetext ='';
$ocutext ='';
	if($degree=="other")
	{
	 $degreetext = $degreeoption;
	}
	else
	{
	$degreetext = $degree;
	}
	if($occupation=="other")
	{
	 $ocutext = $ocuoption;
	}
	else
	{
	$ocutext = $occupation;
	}
$insert = "INSERT into personal(name,age,gender,date,degree,occupation) VALUES ('$name','$age','$gender','$date','$degreetext','$ocutext')";
$check = mysql_query($insert);
	if($check)
	{
	echo 'add';
	}
	else
	{
	echo 'error';
	}
}?><?php
$select = mysql_query("SELECT * from personal");
?>
<table border="1" cellspacing="0">
<tr>
<td><?php echo 'S.No';?></td>
<td><?php echo 'UserID';?></td>
<td><?php echo 'Name';?></td>
<td><?php echo 'Age';?></td>
<td><?php echo 'Gender';?></td>
<td><?php echo 'DOB';?></td>
<td><?php echo 'Degree';?></td>
<td><?php echo 'Occupation';?></td>
</tr>
<?php
$counter=1;$counter1=1; $oit=''; $oitcount=1; 
$onit=''; $onitcount=1;
$odr=''; $odrcount=1;
$oother=''; $oothercount=1;
$db=''; $dbcount=1;
$dbt=''; $dbtcount=1;
$ddr='';$ddrcount=1;
$dother=''; $dothercount=1;
$below=''; $belowcount=1;
$fs=''; $fscount=1;
$ss=''; $sscount=1;
$l=''; $lcount=1;
$gendermale =''; $genderfemale =''; $overallcount=0; $sno=1;
while($row = mysql_fetch_array($select))
{
//print_r($row);
?><tr>
<td><?php echo $sno.'<br>';?></td>
<td><?php echo $row['student_id'].'<br>';?></td>
<td><?php echo $row['name'].'<br>';?></td>
<td><?php echo $row['age'].'<br>';
	if($row['age']<25)
	{
	$below=$belowcount;
	$belowcount++;
	}
	if($row['age']>=25 && $row['age']<=35)
	{
	$fs=$fscount;
	$fscount++;
	}
	if($row['age']>=35 && $row['age']<=45)
	{
	$ss=$sscount;
	$sscount++;
	}
	elseif($row['age']>45)
	{
	$l=$lcount;
	$lcount++;
	}
?></td>
<td><?php echo $row['gender'].'<br>';
	if($row['gender']=="male")
	{
	$gendermale=$counter;
	$counter++;
	}
	elseif($row['gender']=="female")
	{
	$genderfemale=$counter1;
	$counter1++;
	}?>
</td>
<td><?php echo $row['date'].'<br>'; ?></td>
<td><?php
echo $row['degree'].'<br>';
	if($row['degree']=="be")
	{
	$db=$dbcount;
	$dbcount++;
	}
	elseif($row['degree']=="btech")
	{
	$dbt=$dbtcount;
	$dbtcount++;
	}
	elseif($row['degree']=="dr")
	{
	$ddr=$ddrcount;
	$ddrcount++;
	}
	else
	{
	$dother=$dothercount;
	$dothercount++;
	//print_r($oother);
	}
?></td>
<td><?php
echo $row['occupation'].'<br>';
	if($row['occupation']=="it")
	{
	$oit=$oitcount;
	$oitcount++;
	}
	elseif($row['occupation']=="nit")
	{
	$onit=$onitcount;
	$onitcount++;
	}
	elseif($row['occupation']=="dr")
	{
	$odr=$odrcount;
	$odrcount++;
	}
	else
	{
	$oother=$oothercount;
	$oothercount++;
	}
?></td>
</tr><?php
$overallcount++;
$sno++;
}
?>
</table><br><br>
<div class="" style="float:right;">
<div><?php echo'Age group wise'; ?></div>
<?php 
$agecollection = array('Below 25'=>$below,'25-35'=>$fs,'35-45'=>$ss,'Above 45'=>$l);
foreach($agecollection as $key=>$value)
{
$percentage = ($value/$overallcount)*100;
//print_r($percentage);
?>
<div class="" style="float:left; width:80px;">
<?php echo $key .'<br>'; ?>
</div>
<div style="width:100px; height:20px; float:left; border:1px solid;">
<div style="width:<?php echo $percentage; ?>px; height:20px; background:red;">
</div>
</div></br></br>
<?php
}
?>
</div> 
<div class="" style="float:right;">
	<div><?php echo'Gender wise'; ?></div><?php 
	$gendercollection = array('Male'=>$gendermale,'Female'=>$genderfemale,);
	foreach($gendercollection as $key=>$value)
	{
		$percentgender = ($value/$overallcount)*100;?>
		<div class="" style="float:left; width:50px;">
			<?php echo $key .'<br>'; ?>
		</div>
		<div style="width:100px; height:20px; float:left; border:1px solid;">
			<div style="width:<?php echo $percentgender; ?>px; height:20px; background:red;">
			</div>
		</div></br></br>
		<?php
	}
	?>
</div> 
<div class="" style="float:right;">
	<div><?php echo'Degree wise'; ?></div>
	<?php 
	$degreecollection = array('BE'=>$db,'BTECH'=>$dbt,'Dr'=>$ddr,'Others'=>$dother);
	foreach($degreecollection as $key=>$value)
	{
		$percentdegree = ($value/$overallcount)*100;
		?>
		<div class="" style="float:left; width:50px;">
			<?php echo $key .'<br>'; ?>
		</div>
		<div style="width:100px; height:20px; float:left; border:1px solid;">
			<div style="width:<?php echo $percentdegree; ?>px; height:20px; background:red;">
			</div>
		</div></br></br>
		<?php
	}
	?>
</div> 
<div class="" style="float:right;">
	<div><?php echo'Occupation wise'; ?></div>
	<?php 
	$occucollection = array('IT'=>$oit,'NIT'=>$onit,'Dr'=>$odr,'Others'=>$oother);
	foreach($occucollection as $key=>$value)
	{
		$percentoccu = ($value/$overallcount)*100;
		?>
		<div class="" style="float:left; width:50px;">
			<?php echo $key .'<br>'; ?>
		</div>
		<div style="width:100px; height:20px; float:left; border:1px solid;">
			<div style="width:<?php echo $percentoccu; ?>px; height:20px; background:red;">
			</div>
		</div></br></br>
		<?php
	}
	?>
</div> 













 